﻿/*
* CurrencyManage.js
* create by shzhang 2016.04.26
*/
$(function () {
    //announcement
    var divMsg = new jSharp.popUpDiv('divMsg');
    var divAdd = new jSharp.popUpDiv('divAdd');

    //functions

    //Xss反注入

    function filterString(s, maxLen) {
        if (s.length > maxLen) return false;
        s = s.replace(/ /g, '');
        var param = new Array('<', '%3c', '>', '%3e', 'script', 'document', 'eval', '/', '%2f', '//');
        for (var i = 0; i < param.length; i++) {
            var reg = new RegExp(param[i]);
            if (reg.test(s)) return false;
        }
        return true;
    }
    function tips(s) { //消息提示
        divMsg.Show();
        $('#msgContent').html(s);
    }
    function checkLevel() {
        var catList = $('[id$="ddlCat"]');
        var level = $('[id$="ddlItemLevel"]');
        var cat = catList.find("option:selected");
        var l = level.find("option:selected");
        $.get("../Common/AjaxHandler.aspx", {
            handler: "getLevel",
            cid: $(cat).val(),
            level: $(l).val()
        }, function (data) {
            if (data == "NO") {
                tips("若要设置C级或D级产品,请先指定该类别对应的C级或D级供应商");
                level.children("option:selected").removeAttr("selected");
                level.children().first().attr("selected", "selected");
            }
        })
    }
    //handler

    $('#hideMsg').click(function () {
        divMsg.Close();
    })
    $('#hideAdd').click(function () {
        divAdd.Close();
    })
    $('#btnAddItem').click(function () {
        divAdd.Show();
    })
    $('[id$="ddlItemLevel"]').change(function () {
        checkLevel();
    })

} ())
